package com.india.common;

import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.net.URL;
import java.util.Properties;

public class ReadPropertiesFileUtil implements Serializable {

    private static final long serialVersionUID = -928579841720702217L;

    private static final Properties properties = new Properties();

    /**
     * 读配置Web service的Properties配置文件
     * @param clazz
     * @return  返回properties文件
     */
    public static Properties getWebServiceConfig(Class clazz) {
        InputStream fis = null;
        try
        {
            fis = clazz.getClassLoader().getResourceAsStream("resources.properties");
            properties.load(fis);
        } catch (IOException e) {
            e.printStackTrace();

        } finally {
            if (fis != null ){
                try
                {
                    fis.close();
                }
                catch (IOException e)
                {
                    e.printStackTrace();

                }

            }
        }
        return properties;
    }



    public static URL getWsdlFile(String filename) {

        URL url = null;
        try
        {
            return ReadPropertiesFileUtil.class.getClassLoader().getResource(filename);
        }
        catch (Exception e)
        {
            e.printStackTrace();
            return url;
        }
    }

    /**
     * 获取配置文件中的KEY
     * @param key
     * @return 返回properties文件中的KEY对应的值
     */
    public static String getValue(String key) {
        if ( properties.get(key) == null ) {
            getWebServiceConfig(ReadPropertiesFileUtil.class);
        }
        //	System.out.println("OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO  getValue():"+  properties.get(key));
        return (String) properties.get(key);
    }



}
